import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
import http from "@/utils/http.js"

export default new Vuex.Store({
  state: {
    cityId: '310100',
    cityName: '上海',
    isShow: true,
    dataList: [], //保存后端数据状态
    filmTotal: 0,
    filmLoading:false
  },
  mutations: {
    setCityName(store,cityName) {
      // console.log("按规矩办事",store,cityName);
      store.cityName = cityName
    },
    setCityId(store,cityId) {
      store.cityId = cityId
    },
    hide(store) {
        // 隐藏tabBar
      store.isShow = false;
    },
    show(store) {
      store.isShow = true;
    },
    setFilmData(store,filmData) {
      store.dataList = [...store.dataList,...filmData]
      // console.log("setFilm中", filmData);
    },
    setTotal(store,total) {
      store.filmTotal = total;
    },
    clearFilmData(store) {
      store.dataList = [];
      store.filmTotal = 0;
    } 
  },
  actions: {
    // 主要用来做异步处理
    getFilmData(store, options) {
        return http({
            url:`/gateway?cityId=${options.cityId}&pageNum=${options.current}&pageSize=10&type=1&k=5098835`,
            headers:{
                'X-Host': 'mall.film-ticket.film.list'
            }
        }).then((res) => {
            //console.log("dispatch中的请求",res.data.data.films);
            // this.dataList = res.data.data.films
            // // 保存总条数
            // this.total = res.data.data.total
            console.log(res);
            
            store.commit("setFilmData",res.data.data.films)
            store.commit("setTotal",res.data.data.total)
        })
    }
  },
  modules: {
  }
})
